package com.monkeysonnet.b2dFluent;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.physics.box2d.joints.DistanceJoint;
import com.badlogic.gdx.physics.box2d.joints.DistanceJointDef;

public class DistanceJointFactory extends JointFactory<DistanceJointFactory>
{
	private static final DistanceJointDef _initialDef = new DistanceJointDef();
	
	private DistanceJointDef _def;
	
	public DistanceJointFactory()
	{
		this(false);
	}
	
	DistanceJointFactory(boolean managed)
	{
		super(managed);
		_def = new DistanceJointDef();
		super.setDef(_def);
	}	
	
	public DistanceJointFactory localAnchorA (Vector2 v)
	{
		_def.localAnchorA.set(v);
		return this;
	}
	
	public DistanceJointFactory localAnchorA (float x, float y)
	{
		_def.localAnchorA.set(x, y);
		return this;
	}
	
	public DistanceJointFactory localAnchorB (Vector2 v)
	{
		_def.localAnchorB.set(v);
		return this;
	}
	
	public DistanceJointFactory localAnchorB (float x, float y)
	{
		_def.localAnchorB.set(x, y);
		return this;
	}
	
	public DistanceJointFactory frequencyHz(float f)
	{
		_def.frequencyHz = f;
		return this;
	}
	
	public DistanceJointFactory dampingRatio(float r)
	{
		_def.dampingRatio = r;
		return this;
	}
	
	public DistanceJointFactory length(float l)
	{
		_def.length = l;
		return this;
	}
	
	public DistanceJointFactory collideConnected(boolean c)
	{
		_def.collideConnected = c;
		return this;
	}
	
	public DistanceJoint create(World w)
	{
		return (DistanceJoint)w.createJoint(_def);
	}
	
	void clear()
	{
		super.clear(_initialDef);
		_def.dampingRatio = _initialDef.dampingRatio;
		_def.frequencyHz = _initialDef.frequencyHz;
		_def.length = _initialDef.length;
		_def.localAnchorA.set(_initialDef.localAnchorA);
		_def.localAnchorB.set(_initialDef.localAnchorB);
	}

	@Override
	public void free()
	{
		B2d.free(this);
	}
}
